//
//  ViewController.m
//  Example11-2
//
//  Created by 孙晓晔 on 2017/4/14.
//  Copyright © 2017年 孙晓晔. All rights reserved.
//

#import "ViewController.h"

@interface ViewController ()<NSXMLParserDelegate>

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    
    NSString *strPath = [[NSBundle mainBundle] pathForResource:@"my" ofType:@"xml"];
    
    NSURL *url = [NSURL fileURLWithPath:strPath];
    
    NSXMLParser *parser = [[NSXMLParser alloc] initWithContentsOfURL:url];
    
    parser.delegate = self;
    
    [parser parse];
    
}
    
    
-(void)parserDidStartDocument:(NSXMLParser *)parser {
    NSLog(@"开始解析xml");
    
}
    
-(void)parserDidEndDocument:(NSXMLParser *)parser {
    NSLog(@"结束解析xml");
    
}

-(void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary<NSString *,NSString *> *)attributeDict {
    
    NSLog(@"读到标签 = %@", elementName);
}

-(void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName {
    
    NSLog(@"标签 = %@结束", elementName);
}
    
-(void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string {
    NSLog(@"读到字符串 = %@", string);
}
    
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end
